document.addEventListener('DOMContentLoaded', function() {
    // 侧边栏导航切换
    const navLinks = document.querySelectorAll('.admin-nav a');
    const contentSections = document.querySelectorAll('.content-section');

    navLinks.forEach(link => {
        link.addEventListener('click', function(e) {
            e.preventDefault();
            
            // 移除所有活动状态
            navLinks.forEach(link => link.parentElement.classList.remove('active'));
            contentSections.forEach(section => section.classList.remove('active'));
            
            // 添加当前项的活动状态
            this.parentElement.classList.add('active');
            
            // 显示对应的内容区域
            const targetId = this.getAttribute('href').substring(1);
            document.getElementById(targetId).classList.add('active');
        });
    });

    // 用户菜单切换
    const userAvatar = document.querySelector('.user-avatar');
    const userMenu = document.querySelector('.user-menu');

    userAvatar.addEventListener('click', function(e) {
        e.stopPropagation();
        userMenu.style.display = userMenu.style.display === 'block' ? 'none' : 'block';
    });

    // 点击页面其他地方关闭用户菜单
    document.addEventListener('click', function() {
        userMenu.style.display = 'none';
    });

    // 搜索功能
    const searchInput = document.querySelector('.header-search input');
    searchInput.addEventListener('keyup', function(e) {
        if (e.key === 'Enter') {
            // TODO: 实现搜索功能
            console.log('搜索:', this.value);
        }
    });

    // 退出登录
    const logoutLink = document.querySelector('a[href="#logout"]');
    logoutLink.addEventListener('click', function(e) {
        e.preventDefault();
        if (confirm('确定要退出登录吗？')) {
            // TODO: 实现退出登录功能
            window.location.href = 'auth.html';
        }
    });
}); 